export default {
    set(key, value) {
        let v = null;
        if (typeof value === 'object') {
            try {
                v = JSON.stringify(value);
            } catch (e) {
                console.log(v);
            }
        } else if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
            v = value;
        }
        localStorage.setItem(key, v);
    },
    get(key) {
        let v = localStorage.getItem(key);
        if (typeof v === 'string') {
            try {
                if (v.search(/^\{/) > -1 || v.search(/^\[/) > -1) {
                    return JSON.parse(v);
                } else {
                    return v;
                }
            } catch (e) {
                console.log(v);
            }
        }
        return null;
    },
    remove(key) {
        localStorage.removeItem(key);
    }
};
